package com.briup.day09;

/**
 * @author ThinkBook
 */
public class Test04_Variable {
    public static int getSum(int... arr){
        System.out.println(arr);
// 5
        System.out.println(arr.length);
        int sum = 0;
        for(int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }
    public static double getAvg(int[] arr){
        double sum = 0;
        for(int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum/arr.length;
    }
    public static void main(String[] args) {
        int[] array = {1,3,2,4,6};

        //1.调用普通方法实现功能
        double avg = getAvg(array);
        System.out.println(avg);
        System.out.println("------------");

        //2.使用可变参数列表
        int sum = getSum(array);
        System.out.println(sum);
        System.out.println("------------");

        //3.可变参数列表特殊形式
        sum = getSum(1,3,2,4,6); //依旧能够成功
        System.out.println(sum);
    }
}
